package config

import (
	"github.com/spf13/viper"
	"log"
)

type Config struct {
	Mysql
	Redis
}
type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}
type Redis struct {
	Addr     string
	Password string
	Db       int
}

var Appconf Config

func Init() {
	viper.SetConfigFile("./config/config.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		log.Println("配置文件读取失败")
		return
	}
	err = viper.Unmarshal(&Appconf)
	if err != nil {
		log.Println("配置文件解析失败")
		return
	}
	log.Println("配置文件读取成功")
}
